//
// Created by 11510 on 2024/6/13.
//

#include "Line.h"
#include <iostream>
using std::cout;
using std::endl;
/**
 * 定义内部类
 */
class Line::LineImpl{
//*************************这是想要隐藏的内容*********************************************
private:
    class Point{
    public:
        Point(int x ,int y): _ix(x), _iy(y){
            cout << "Point(int,int)" << endl;
        }

        void print(){
            cout << "(" << _ix
                 << "," << _iy
                 << ")";
        }

        ~Point(){
            cout << "~Point()" << endl;
        }

    private:
        int _ix;
        int _iy;
    };
    Point _pt1;
    Point _pt2;
//************************************************************************************
public:
    LineImpl(int x1,int y1,int x2,int y2): _pt1(x1,y1), _pt2(x2,y2){
        cout << "Line::LineImpl(int*4)" << endl;
    }

    void printLine(){
        _pt1.print();
        cout << "------>";
        _pt2.print();
        cout << endl;
    }

    ~LineImpl(){
        cout << "~Line::LineImpl()" << endl;
    }

};


Line::Line(int x1,int y1,int x2,int y2): _pimpl(new LineImpl(x1,y1,x2,y2)){
    cout << "Line(int*4)" << endl;
}


Line::~Line(){
    cout << "~Line()" << endl;
    if(_pimpl){
        delete _pimpl;
        _pimpl = nullptr;
    }
}

/**
 * 外部类调用内部类的方法
 */
void Line::printLine() const{
    //调用LineImpl的printLine
    _pimpl->printLine();
}